(function(){
	var skill = {
		save:function(){
			db.update(config.dbname.user,this._id,this);
		},
		destroy:function(){
			//从评论者的评论列表中删除
			var commenter = this.getCommenter();
			commenter._removeComment(this._id);
			//如果是回复他人的评论，则从别人的“收到的回复”列表中删除
			if (this.reply_id) {
				var CommentCon = require("./_con");
				var replyComment = CommentCon.get(this.reply_id);
				if (!replyComment) {
					throwCusError("找不到对应评论")
				}
				replyComment.removeReply(this._id);
			}
			db.remove(config.dbname.user,this._id);
		},
		setInfo:function(info) {
			var self = this;
			info&&Object.keys(info).forEach(function(key){
				if (self.hasOwnProperty(key)) {
					self[key] = info[key];
				}
			})
			self.save();
		},
		//获取评论者
		getCommenter:function(){
			//评论者对象
			var Constructor = require("../"+this.type+"/_con");
			if (Constructor) {
				var commenter = Constructor.get(this.commenter_id);
			}else{
				throwCusError("找不到指定类");
			}
			return commenter;
		},
		//添加子评论，并通知评论者“收到回复”。非安全（因为发起者不可能会comment自身，而是user或者bus等可活动对象）
		_addComment:function(comment_id){
			var comments = this.comments||(this.comments = []);
			comments.unshift(comment_id);
			//通知评论者“收到回复”
			var commenter = this.getCommenter();
			commenter._addReply(this._id);
			this.save();
		},
		//获取评论详情，包括递归获取子评论
		getDetail:function(){
			var comment = $Object.clone(this);
			if (comment.isAny) {
				//匿名
				delete comment.commenter_id;
				delete comment.type;
			}else{
				//获取用户详情
				var commenter = require("../"+comment.type+"/_con").get(comment.commenter_id);
				comment.commenter_info = {name:commenter.info.name||(commenter.getName&&commenter.getName()),_id:commenter._id};
			}
			//递归取出全部子评论
			var CommentCon = require("./_con");
			comment.comments = comment.comments.map(function(child_comment_id,index){
				var childComment = CommentCon.get(child_comment_id._id||child_comment_id);
				console.log("child_comment_id:",child_comment_id);
				return childComment.getDetail();
			});
			return comment;
		},
	}
	module.exports = skill;

	var db = require("../db/index");
	var config = require("../_include/config");
	var UserAddressCon = require("../user_address/_con");
	var AchCon = require("../ach/_con");
	var $Object = require("../_include/$.Object");

}());
